1 module unde.games.dizzy.omega.animations.water;
2 
3 import derelict.opengl3.gl;
4 import std.math;
5 import std.stdio;
6 import unde.games.object;
7 import unde.games.renderer;
8 import unde.global_state;
9 
10 class Water:StaticGameObject
11 {
12     float[3][][] dup_vertices;
13     float surface;
14     string model;
15 
16     float min_x, min_y, max_x, max_y;
17     
18     this(MainGameObject root, string model, float surface)
19     {
20         this.surface = surface;
21         this.model = model;
22         models[model] = root.models[model];
23         foreach(ref object; models[model].objects)
24         {
25             dup_vertices ~= cast(float[3][]) object.vertices.dup();
26             
27             foreach(i, ref vertice; object.vertices)
28             {
29                 if (-vertice[0] < min_x || min_x.isNaN) min_x = -vertice[0];
30                 if (-vertice[0] > max_x || max_x.isNaN) max_x = -vertice[0];
31                 if (vertice[1] < min_y || min_y.isNaN) min_y = vertice[1];
32                 if (vertice[1] > max_y || max_y.isNaN) max_y = vertice[1];
33             }
34         }
35         super(root);
36     }
37 
38     override void draw(GlobalState gs)
39     {
40         if (root.scrx < min_x - 30.0 ||
41             root.scrx > max_x + 30.0 ||
42             root.scry < min_y - 18.0 ||
43             root.scry > max_y + 18.0) return;
44 
45         glPushMatrix();
46         recursive_render(gs, models[model], null, null, true);
47         glPopMatrix();
48     }
49     
50     override bool tick(GlobalState gs)
51     {
52         if (root.scrx < min_x - 30.0 ||
53             root.scrx > max_x + 30.0 ||
54             root.scry < min_y - 18.0 ||
55             root.scry > max_y + 18.0) return true;
56         
57         foreach(o, ref object; models[model].objects)
58         {
59             foreach(i, ref vertice; object.vertices)
60             {
61                 if (vertice[1] > surface)
62                     vertice[1] = dup_vertices[o][i][1] + 0.5f*sin(vertice[0] + root.frame/100.0)*sin(vertice[2] + root.frame/200.0);
63             }
64         }
65         return true;
66     }
67 }